interface DebugState {
  data: any
}

export const useDebugStore = defineStore('debug-store', {
  state: (): DebugState => ({
    data: null
  }),
  actions: {
    setData(payload: any) {
      const maybeStore = payload as any
      // 若传入的是 Pinia store 实例，则只存储其 $state，避免循环引用
      this.data = (maybeStore && typeof maybeStore === 'object' && ('$state' in maybeStore))
        ? maybeStore.$state
        : payload
    }
  }
})